package com.fy.oa.zc.log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import com.fy.oa.zc.exception.FyOAException;

public final class FyOAFileLoggerImpl implements FyOAFileLogger {
	private String logPath;

	public void setLogPath(String logPath) {
		this.logPath = logPath;
	}

	@Override
	public void writeMessage(String msg, FyOAException e) throws IOException {
		synchronized (this) {
			File file = new File(
					logPath + "/" + new java.sql.Timestamp(java.util.Calendar.getInstance().getTimeInMillis())
							.toString().substring(0, 10) + ".log");
			if (!file.exists()) {
				file.createNewFile();
				FileOutputStream fos = new FileOutputStream(file, true);
				PrintStream ps = new PrintStream(fos, true, "utf-8");
				ps.write(msg.getBytes());
				e.printStackTrace(ps);
				ps.flush();
				ps.close();
			}
		}
	}

	@Override
	public void writeMessage(String msg) {
		// String today = new
		// java.sql.Timestamp(java.util.Calendar.getInstance().getTimeInMillis()).toString().substring(0,
		// 10);
		// if (logFileName == null||!today.equals(logFileName)) {
		//
		// }
		// File file = new File(logPath + "/"
		// + new
		// java.sql.Timestamp(java.util.Calendar.getInstance().getTimeInMillis()).toString().substring(0,
		// 10)
		// + ".log");
		// if (!file.exists()) {
		// try {
		// file.createNewFile();
		// FileOutputStream fos = new FileOutputStream(file, true);
		// PrintStream ps = new PrintStream(fos, true, "utf-8");
		// ps.write(msg.getBytes());
		// ps.flush();
		// ps.close();
		// } catch (IOException e1) {
		// e1.printStackTrace();
		// }
		// }
	}

}
